<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col
        :xs="24"
        :sm="24"
        :md="8"
        :lg="6"
        :xl="5"
        style="margin-bottom: 10px"
      >
        <!-- <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div style="text-align: center">
              <div class="el-upload">
                <img
                  :src="
                    user.avatarName
                      ? baseApi + '/avatar/' + user.avatarName
                      : Avatar
                  "
                  title="点击上传头像"
                  class="avatar"
                  @click="toggleShow"
                />
                <myUpload
                  v-model="show"
                  :url="updateAvatarApi"
                  @crop-upload-success="cropUploadSuccess"
                />
              </div>
            </div>
            <ul class="user-info">
              <li>
                <div style="height: 100%">
                  <svg-icon icon-class="login" /> 登录账号
                  <div class="user-right">{{ user.username }}</div>
                </div>
              </li>
              <li>
                <svg-icon icon-class="user1" /> 用户昵称
                <div class="user-right">{{ user.nickName }}</div>
              </li>
              <li>
                <svg-icon icon-class="dept" /> 所属部门
                <div class="user-right">{{ user.dept.name }}</div>
              </li>
              <li>
                <svg-icon icon-class="phone" /> 手机号码
                <div class="user-right">{{ user.phone }}</div>
              </li>
              <li>
                <svg-icon icon-class="email" /> 用户邮箱
                <div class="user-right">{{ user.email }}</div>
              </li>
              <li>
                <svg-icon icon-class="anq" /> 安全设置
                <div class="user-right">
                  <a @click="$refs.pass.dialog = true">修改密码</a>
                  <a @click="$refs.email.dialog = true">修改邮箱</a>
                </div>
              </li>
            </ul>
          </div>
        </el-card> -->
      </el-col>
      <el-col :xs="24" :sm="24" :md="16" :lg="18" :xl="19">
        <!--    用户资料    -->
        <el-card class="box-card">
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="用户资料" name="first">
              <el-form
                ref="form"
                :model="form"
                :rules="rules"
                style="margin-top: 10px;"
                size="small"
                label-width="65px"
              >
                <el-form-item label="昵称" prop="nickName">
                  <el-input v-model="form.nickName" style="width: 35%" />
                  <span style="color: #C0C0C0;margin-left: 10px;"
                    >用户昵称不作为登录使用</span
                  >
                </el-form-item>
                <el-form-item label="手机号" prop="phone">
                  <el-input v-model="form.phone" style="width: 35%;" />
                  <span style="color: #C0C0C0;margin-left: 10px;"
                    >手机号码不能重复</span
                  >
                </el-form-item>
                <el-form-item label="性别">
                  <el-radio-group v-model="form.gender" style="width: 178px">
                    <el-radio label="男">男</el-radio>
                    <el-radio label="女">女</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="">
                  <el-button
                    :loading="saveLoading"
                    size="mini"
                    type="primary"
                    @click="doSubmit"
                    >保存配置</el-button
                  >
                </el-form-item>
              </el-form>
            </el-tab-pane>
            <!--    操作日志    -->
            <el-tab-pane label="操作日志" name="second">
              <el-table
                :data="dataList"
                border
                v-loading="dataListLoading"
                style="width: 100%"
              >
                <el-table-column
                  prop="id"
                  header-align="center"
                  align="center"
                  width="80"
                  label="ID"
                >
                </el-table-column>
                <el-table-column
                  prop="username"
                  header-align="center"
                  align="center"
                  label="用户名"
                >
                </el-table-column>
                <el-table-column
                  prop="operation"
                  header-align="center"
                  align="center"
                  label="用户操作"
                >
                </el-table-column>
                <el-table-column
                  prop="method"
                  header-align="center"
                  align="center"
                  width="150"
                  :show-overflow-tooltip="true"
                  label="请求方法"
                >
                </el-table-column>
                <el-table-column
                  prop="params"
                  header-align="center"
                  align="center"
                  width="150"
                  :show-overflow-tooltip="true"
                  label="请求参数"
                >
                </el-table-column>
                <el-table-column
                  prop="time"
                  header-align="center"
                  align="center"
                  label="执行时长"
                >
                 <template slot-scope="scope">
                    <el-tag v-if="scope.row.time <= 300">{{ scope.row.time }}ms</el-tag>
                    <el-tag v-else-if="scope.row.time <= 1000" type="warning">{{ scope.row.time }}ms</el-tag>
                    <el-tag v-else type="danger">{{ scope.row.time }}ms</el-tag>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="ip"
                  header-align="center"
                  align="center"
                  width="150"
                  label="IP地址"
                >
                </el-table-column>
                <el-table-column
                  prop="createDate"
                  header-align="center"
                  align="center"
                  width="180"
                  label="创建时间"
                >
                </el-table-column>
              </el-table>
              <el-pagination
                @size-change="sizeChangeHandle"
                @current-change="currentChangeHandle"
                :current-page="pageIndex"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                :total="totalPage"
                layout="total, sizes, prev, pager, next, jumper"
              >
              </el-pagination>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
    <!-- <updateEmail ref="email" :email="user.email" />
    <updatePass ref="pass" /> -->
  </div>
</template>

<script>
import Avatar from "@/assets/images/avatar.png";
export default {
  name: "Center",
  data() {
    // 自定义验证
    const validPhone = (rule, value, callback) => {
      if (!value) {
        callback(new Error("请输入电话号码"));
      } else if (!isvalidPhone(value)) {
        callback(new Error("请输入正确的11位手机号码"));
      } else {
        callback();
      }
    };
    return {
      dataListLoading: false,
      dataList: [],
      updateAvatarApi: "",
      user: {},
      show: false,
      Avatar: Avatar,
      activeName: "first",
      saveLoading: false,
      form: {},
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataForm: {
        key: ""
      },
      rules: {
        nickName: [
          { required: true, message: "请输入用户昵称", trigger: "blur" },
          { min: 2, max: 20, message: "长度在 2 到 20 个字符", trigger: "blur" }
        ],
        phone: [{ required: true, trigger: "blur", validator: validPhone }]
      }
    };
  },
  computed: {
    a: {
      get() {
        return this.$store.state.user;
      }
    }
  },
  mounted(){
    console.log('a',this.a)
  },
  methods: {
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.initULog();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.initULog();
    },
    //初始化操作日志列表
    initULog() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/sys/log/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.dataForm.key
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    toggleShow() {
      this.show = !this.show;
    },
    handleClick(tab, event) {
      if (tab.name === "second") {
        this.initULog();
      }
    },
    cropUploadSuccess(jsonData, field) {}
  },
  created() {
    this.form = {
      id: this.user.id,
      nickName: this.user.nickName,
      gender: this.user.gender,
      phone: this.user.phone
    };
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}
.user-info {
  padding-left: 0;
  list-style: none;
  li {
    border-bottom: 1px solid #f0f3f4;
    padding: 11px 0;
    font-size: 13px;
  }
  .user-right {
    float: right;
    a {
      color: #317ef3;
    }
  }
}
</style>
